package com.fafa.swing.richclient02;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author : fafa
 * @version V1.0
 * @Project: SwingTest
 * @Package com.fafa.swing.richclient02
 * @Description: ComponentTest
 * @date Date : 2019年11月27日 21:53
 */
public class ComponentTest {

    private static JButton[] bs = {new JButton("确定"),new JButton("取消"), new JButton("重置")};

    public static void main(String[] args) {
        JFrame frame = new JFrame("OvalTest");
        JPanel panel1 = new JPanel();
        OvalComponent ovalComponent = new OvalComponent();
        addPanel(panel1, ovalComponent, BorderLayout.CENTER);

        JButton button1 = new JButton("Button");
        button1.setPreferredSize(new Dimension(100,20));
        JButton button2 = new JButton("Button2");
        HighlightedButton highlightedButton = new HighlightedButton("HighlightedButton");
        highlightedButton.setPreferredSize(new Dimension(100,20));

        JPanel panel2 = new JPanel();

        GridBagLayout gridBagLayout = new GridBagLayout();
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        frame.setLayout(gridBagLayout);
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.fill = GridBagConstraints.BOTH;
        gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
        gridBagLayout.setConstraints(panel1, gridBagConstraints);
        panel1.add(ovalComponent);
        frame.add(panel1);
        gridBagConstraints.weightx = 0.1/5;
        gridBagConstraints.weighty = 0.1/5;
        gridBagConstraints.gridwidth = 1;

        //gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = GridBagConstraints.EAST;
        gridBagLayout.setConstraints(button1, gridBagConstraints);
        gridBagLayout.setConstraints(highlightedButton, gridBagConstraints);
        frame.add(button1);
        frame.add(highlightedButton);

        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showOptionDialog(null,"确认查询",
                        "确认",1,1,null, bs, bs[0]);
            }
        });

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBounds(600,200,355,400);
        frame.setVisible(true);
    }

    public static void addPanel(JPanel panel, JComponent component, String layout){
        panel.setLayout(new BorderLayout(0,0));
        panel.setBorder(new EmptyBorder(5,5,5,5));
        panel.add(component, layout);
    }
}
